import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index'
const Index = ()=>import('@/views/Index')
const User = ()=>import('@/views/User')
const Cinema = ()=>import('@/views/Cinema')
const Hall = ()=>import('@/views/Hall')
const Login = ()=>import('@/views/login/Login')
const UserCenter = ()=>import('@/views/user/UserCenter')
const SelectSeat = ()=>import('@/views/SelectSeat')
const SubOrder = ()=>import('@/views/SubOrder')
const ResultPage = ()=>import('@/views/ResultPage')
const OrderList = ()=>import('@/views/OrderList')
const Recharge = ()=>import('@/views/Recharge')
const NotFount = () => import('@/views/error/404')
const ForbiddenPage = () => import('@/views/error/403')
const SystemErrorPage = () => import('@/views/error/500')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    component: Index
  },
  {
    path: '/cinema',
    name: 'Cinema',
    component: Cinema,
    props: (route) => ({ movieId: route.query.mid })
  },
  {
    path: '/hall',
    name: 'Hall',
    component: Hall,
    props: (route) => ({ movieId: route.query.mid,cinemaId:route.query.cid })
  },
  {
    path: '/seat',
    name: 'SelectSeat',
    component: SelectSeat,
    props: (route) => ({ movieShowId: route.query.msid,hallId:route.query.hid,movieId:route.query.mid })
  },
  {
    path: '/order',
    name: 'SubOrder',
    component: SubOrder,
  },
  {
    path: '/orderList',
    name: 'OrderList',
    component: OrderList,
  },
  {
    path: '/recharge',
    name: 'Recharge',
    component: Recharge,
  },
  {
    path: '/result',
    name: 'ResultPage',
    component: ResultPage,
  },
  {
    path: '/user',
    name: 'User',
    component: User,
    children:[]
  },
  {
    path: '/userCenter',
    name: 'UserCenter',
    component: UserCenter
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path:'/403',
    name:'403',
    component:ForbiddenPage
  },
  {
    path:'/500',
    name:'500',
    component:SystemErrorPage
  },
  {
    path:'*',
    name:'404',
    component:NotFount
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if (store.state.system.staticData.length===0){
    store.dispatch('GetStaticData')
  }
  next()
})
export default router
